<?php
/**
 * 支付相关控制器
 * 
 */
namespace app\home\controller;

use app\home\HomeController;
use think\facade\Db;
use think\facade\Cache;

class Pay extends HomeController
{
     /**
     * payoneer createOrder 
     * @return mixed
     */
    public function payoneerCreateorder()
    {
		$id 	= input('id');
        $amount = 100;			//您系统的订单金额
		$order	= [];			//您系统的订单信息

        if(empty($amount)){

            return json(['code'=>-1,'msg'=>"The parameter is invalid, please refresh the page."]);
        }

        $payoneer = new \Payoneer();

        $rs = $payoneer->createPayment($amount,$order);

        return json($rs);
    }
	
	
	/*
    * payoneer支付成功回调函数
    * 
    * */
    public function payoneerNotification(){

		$token  	= input('token');
        $jsonData  	= file_get_contents("php://input");
 
        $data = json_decode($jsonData,true);

        if($data['statusCode'] != 'charged' || $data['interactionReason'] != 'OK' || $data['interactionCode'] != 'PROCEED' || $data['reasonCode'] != 'debited'){
            header("HTTP/1.1 200 OK");
            exit;
        }
		
		//验证参数不存在
		if($token==''){
            header("HTTP/1.1 200 OK");
            exit;
		}
		
		
		//token验签(根据自己实际情况编写，官方没提供验签算法)



		$order_code = $data['transactionId'];		//发起支付时，传的订单编号等参数

		/**
		*
		*具体的逻辑实现
		*
		*/


        header("HTTP/1.1 200 OK");
    }

}